package com.web.exiaodao.business.service.impl;

import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.web.webstart.base.service.impl.BaseService;
import com.web.webstart.base.exception.BusinessException;
import com.web.webstart.base.constant.XaConstant;
import com.web.webstart.base.util.jpa.DynamicSpecifications;
import com.web.webstart.base.util.jpa.SearchFilter;
import com.web.webstart.base.util.jpa.SearchFilter.Operator;
import com.web.webstart.base.util.result.XaResult;
import com.web.webstart.base.util.XaUtil;
import com.web.exiaodao.business.entity.ShopStandardName;
import com.web.exiaodao.business.repository.ShopStandardNameRepository;
import com.web.exiaodao.business.service.ShopStandardNameService;

@Service("ShopStandardNameService")
@Transactional(readOnly = false)
public class ShopStandardNameServiceImpl extends BaseService<ShopStandardName> implements ShopStandardNameService {

    private static final Logger LOGGER = Logger.getLogger(ShopStandardNameServiceImpl.class);

    @Autowired
    private ShopStandardNameRepository shopStandardNameRepository;

    /**
     * 查询单条ShopStandardName信息
     * //@param tId
     *
     * @return 返回单个ShopStandardName对象
     * @throws BusinessException
     */
    @Transactional(readOnly = true, rollbackFor = Exception.class)
    public XaResult<ShopStandardName> findOne(Long modelId) throws BusinessException {
        throw new BusinessException(XaConstant.Message.error_method_no_impl);
    }

    /**
     * 分页查询状态非status的ShopStandardName数据
     *
     * @param status
     * @param filterParams
     * @param pageable
     * @return 返回对象ShopStandardName集合
     * @throws BusinessException
     */
    @Transactional(readOnly = true, rollbackFor = Exception.class)
    public XaResult<Page<ShopStandardName>> findListNEStatusByFilter(
            Integer status, Map<String, Object> filterParams, Pageable pageable) throws BusinessException {
        Map<String, SearchFilter> filters = SearchFilter.parse(filterParams);
        if (status == null) {// 默认显示非删除的所有数据
            status = XaConstant.Status.delete;
        }
        filters.put("status", new SearchFilter("status", Operator.NE, status));
        Page<ShopStandardName> page = shopStandardNameRepository.findAll(DynamicSpecifications
                .bySearchFilter(filters.values(), ShopStandardName.class), pageable);
        XaResult<Page<ShopStandardName>> xr = new XaResult<Page<ShopStandardName>>();
        xr.setObject(page);
        LOGGER.info("后台----->分页查询实体集合（状态不等于）----->ShopStandardName");
        return xr;
    }

    /**
     * 分页查询状态status的ShopStandardName数据
     *
     * @param status
     * @param filterParams
     * @param pageable
     * @return 返回对象ShopStandardName集合
     * @throws BusinessException
     */
    @Transactional(readOnly = true, rollbackFor = Exception.class)
    public XaResult<Page<ShopStandardName>> findListEQStatusByFilter(
            Integer status, Map<String, Object> filterParams, Pageable pageable) throws BusinessException {
        Map<String, SearchFilter> filters = SearchFilter.parse(filterParams);
        if (status == null) {// 默认显示正常数据
            status = XaConstant.Status.valid;
        }
        filters.put("status", new SearchFilter("status", Operator.EQ, status));
        Page<ShopStandardName> page = shopStandardNameRepository.findAll(DynamicSpecifications
                .bySearchFilter(filters.values(), ShopStandardName.class), pageable);
        XaResult<Page<ShopStandardName>> xr = new XaResult<Page<ShopStandardName>>();
        xr.setObject(page);
        LOGGER.info("后台----->分页查询实体集合（状态等于）----->ShopStandardName");
        return xr;
    }

    /**
     * 保存ShopStandardName信息
     *
     * @param model
     * @return
     * @throws BusinessException
     */
    @Transactional(rollbackFor = Exception.class)
    public XaResult<ShopStandardName> saveOrUpdate(ShopStandardName model) throws BusinessException {
        ShopStandardName obj = null;
        if (XaUtil.isNotEmpty(model.getId())) {
            obj = shopStandardNameRepository.findOne(model.getId());
        } else {
            obj = new ShopStandardName();
        }
        obj.setShopId(XaUtil.isNotEmpty(model.getShopId()) ? model.getShopId() : obj.getShopId());
        obj.setShopStandsName(XaUtil.isNotEmpty(model.getShopStandsName()) ? model.getShopStandsName() : obj.getShopStandsName());
        obj = shopStandardNameRepository.save(obj);
        XaResult<ShopStandardName> xr = new XaResult<ShopStandardName>();
        xr.setObject(obj);
        LOGGER.info("后台新增或编辑数据成功！");
        return xr;
    }

    /**
     * 修改ShopStandardName状态，可一次修改多条   3删除  -1锁定  1正常
     * //@param userId
     *
     * @param modelIds
     * @param status
     * @return 返回ShopStandardName对象
     * @throws BusinessException
     */
    @Transactional(rollbackFor = Exception.class)
    public XaResult<ShopStandardName> multiOperate(
            String modelIds, Integer status) throws BusinessException {
        throw new BusinessException(XaConstant.Message.error_method_no_impl);
    }

}
